package com.yanqu.road.server.channelserver.cmd.activity.entername;

import com.yanqu.road.entity.activity.entername.EnterNameParam;
import com.yanqu.road.logic.activity.entername.ChannelEnterNameHelper;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.manager.activity.entername.ChannelEnterNameMgr;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = ChannelProtocol.N_ENTER_NAME_ADD_AUTO, desc = "活动自动报名")
public class ChannelEnterNameAutoAddCmd extends ChannelCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {


        EnterNameProto.ChannelEnterNameAutoAddReqMsg reqMsg = EnterNameProto.ChannelEnterNameAutoAddReqMsg.parseFrom(packet.getBytes());

        if(reqMsg.getUserList().size() > 0){
            List<EnterNameParam> userList = new ArrayList<>();
            for (EnterNameProto.ChannelEnterNameAddMsg msg : reqMsg.getUserList()) {
                EnterNameParam param = ChannelEnterNameHelper.parseFromMsg(
                        reqMsg.getActivityId(),
                        reqMsg.getChannelId(),
                        reqMsg.getServerId(),
                        msg);
                userList.add(param);
            }

            ChannelEnterNameMgr.enterNameBatchAdd(reqMsg.getActivityId(), reqMsg.getChannelId(), reqMsg.getServerId(), userList)
;        }
    }

    @Override
    public void sendData() {

    }
}
